// src/mock/user.ts
import { MockMethod } from 'vite-plugin-mock'

export default [
  {
    url: '/api/list',
    method: 'get',
    response: () => {
    // 调用一次返回10条数据
    const items = Array.from({ length: 10 }, (_, i) => ({
      id: 100 + i,
      content: `这是第${i + 1}条评论`,
      image: `https://picsum.photos/300/400?random=${i + 1}`,
      width: 300,
      height: 400
    }))
      return {
      "code": 200,
      "data": {
        "list": items,
        "page": 1,
        "total": 10,
        "pageSize": 10
      }
    }
    }
  },
  {
    url: '/api/login',
    method: 'post',
    timeout: 1000,
    response: ({ body }: { body: { username: string; password: string } }) => {
      if (body.username === 'admin' && body.password === '123456') {
        return {
          code: 200,
          data: {
            token: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
          }
        }
      }
      return {
        code: 401,
        message: 'Invalid credentials'
      }
    }
  }
] as MockMethod[]